<?php
// +----------------------------------------------------------------------
// | Bwsaas
// +----------------------------------------------------------------------
// | Copyright (c) 2015~2020 http://www.buwangyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Gitee ( https://gitee.com/buwangyun/bwsaas )
// +----------------------------------------------------------------------
// | Author: buwangyun <hnlg666@163.com>
// +----------------------------------------------------------------------
// | Date: 2020-9-28 10:55:00
// +----------------------------------------------------------------------

namespace app\api\controller;

use buwang\base\Api;
use app\common\model\User;

class Basic extends Api
{
    protected $uid;
    protected function initialize()
    {
        parent::initialize();
        $this->uid = isset($this->user->id) ? $this->user->id : 0;
    }

    /**
     * 通过ucode获取邀请人用户信息
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function getUcodeUser()
    {
        self::isUserAuth();
        $ucode = de_code(strtoupper($this->request->param('ucode/s')));
        if (empty($ucode)) {
            return $this->code(204)->error('邀请码为空');
        }
        $result = User::where(['id' => $ucode])->field('id,nickname,invite_code,avatar')->find();
        if (empty($result)) {
            return $this->code(204)->error('没有查询到用户内容');
        } else {
            return $this->success('获取成功');
        }
    }
}